package club.kingyin.easycache.method.core;

import club.kingyin.easycache.cache.ValueSerializer;
import club.kingyin.easycache.component.CachePostProcess;
import club.kingyin.easycache.exception.InitException;
import club.kingyin.easycache.key.InvokePostProcess;
import club.kingyin.easycache.method.CacheMethod;
import club.kingyin.easycache.method.MethodEasyCache;

// XXX: 2022/8/21 需要重构狗，初始化逻辑混乱，生命周期可用性差
@Deprecated
public abstract class CacheEnhancer extends MethodEasyCache implements Lifecycle, MethodEasyCacheDeploy, SerializerDeploy {


    private InvokePostProcess<CacheMethod>[] invokePostProcesses;

    public CacheEnhancer() {
        init();
        if (!checkSerializerInit()) {
            throw new InitException("CacheEnhancer 序列化器初始化失败");
        }
        setSerializer(getSerializer());
    }

    boolean checkSerializerInit() {
        return serializer != null;
    }

    protected abstract void init();

    @Override
    public void setCachePostProcesses(CachePostProcess[] cachePostProcesses) {
        super.setCachePostProcesses(cachePostProcesses);
    }

    public void setInvokePostProcesses(InvokePostProcess<CacheMethod>[] invokePostProcesses) {
        this.invokePostProcesses = invokePostProcesses;
    }

    @Override
    public CachePostProcess[] getCachePostProcessor() {
        return super.getPostProcesses();
    }

    @Override
    public InvokePostProcess<CacheMethod>[] getInvokePostProcessor() {
        return invokePostProcesses;
    }

    @Override
    public ValueSerializer getSerializer() {
        return serializer;
    }

    @Override
    public MethodEasyCache getMethodEasyCache() {
        return this;
    }
}
